<!DOCTYPE html>

<title>凹语言生命游戏</title>

<div style="text-align: center;">
  <canvas id="canvas" width="400" height="400"></canvas>
  <div>R键:重置; 空格键:暂停</div>
</div>

<script type="module">
  import { WaApp } from "./life.js";

  let app = new WaApp();

  window.onload = () => {
    app.init().then((result) => {
      app.main();

      let keyPausing = false;
      let preTimeStamp = 1;

      // 初始化
      app.LifeInit(400, 400, preTimeStamp);

      document.addEventListener('keyup', (event) => {
        switch (event.key) {
          case ' ':
            keyPausing = !keyPausing;
            app.LifePausing()
            break;
          case 'r':
            app.LifeInit(400, 400, preTimeStamp);
            break;
        }
      });

      let stepAnima = function (timeStamp) {
        app.LifeStep();
        preTimeStamp = timeStamp;
        window.requestAnimationFrame(stepAnima);
      }
      window.requestAnimationFrame(stepAnima);
    })
  };
</script>
